package com.yu.myiptv;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtils {
    public static List<Channel> loadChannelsFromFile(Context context) {
        List<Channel> channels = new ArrayList<>();
        try {
            AssetManager am = context.getAssets();
            InputStream is = am.open("channels.txt");
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = reader.readLine()) != null) {
                // 假设每行数据为"channel_id,name,url"
                String[] parts = line.split(",");
                if (parts.length == 3) {
                    Channel channel = new Channel(parts[0],parts[1],parts[2]);
                    channels.add(channel);
                }
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return channels;
    }
}
